﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;


namespace CAXMLDemo
{
    class Program
    {
        /// <summary>
        /// OO五大原则：
        /// 单一职责原则
        /// 依赖倒置原则
        /// 开放封闭原则
        /// 接口隔离原则
        /// Liskov替换原则
        /// </summary>
        /// <param name="args"></param>

        static void Main(string[] args)
        {
            string xmlFilePath = AppDomain.CurrentDomain.BaseDirectory + "User.xml";
           
            XElement xmlData = XElement.Parse(System.IO.File.ReadAllText(xmlFilePath));
            var users = from user in xmlData.Descendants("User")
                        where int.Parse(user.Element("Age").Value) < 30
                        orderby int.Parse(user.Element("Age").Value) descending
                        select new
                        {
                            Name = user.Element("Name").Value,
                            Age = user.Element("Age").Value
                        };
            foreach (var user in users)
            {
                Console.WriteLine("姓名: " + user.Name + "    年龄：" + user.Age.ToString());
            }

            Console.ReadKey();
        }
    }
}
